// models/reservation/index.js

var date = new Date();
var nowDate = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
var app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    courseInfo:{
      type: Object,
      default: {}
    },
    showMask: {
      type: Boolean,
      default: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    date: nowDate,
    startDate: nowDate,
    time: '12:00'
  },

  /**
   * 组件的方法列表
   */
  methods: {
  //時間選擇
    bindTimeChange: function(e) {
      this.setData({
        time: e.detail.value
      })
    },
    //日期選擇
    bindDateChange: function(e) {
      this.setData({
        date: e.detail.value
      })
    },
    // 免费体验预约
    formSubmit: function(e) {
      let that = this;
      let formData = {};
      formData.date = this.data.date;
      formData.time = this.data.time;
      formData.mobile = e.detail.value.mobile;
      formData.name = e.detail.value.name;
      formData.courseId = that.data.courseInfo.courseId;

      if(!formData.mobile) {
        app.alert('请填写联系电话'); return false;
      }

      if(!formData.name) {
        app.alert('请填写联系人'); return false;
      }

      app.request({
        url: 'course/reservation',
        data: formData,
        sCallback: (res) => {
          if(res.code == 1) {
            wx.showToast({
              title: res.msg,
              icon: "success",
              duration: 1500,
            })
            that.setData({
              showMask: false
            })
          } else {
            app.alert(res.data.info)
          }
        }
      })
    },
    show() {
      // this.setData({
      //   showMask: true
      // })
    },
    hide() {
      this.setData({
        showMask: false
      })
      this.triggerEvent('hide', {
       "showMask": false
      })
    }
  }
})
